#include "SocketInterface.h"
#include "GASocketOper.h"

void* SocketInterface_NewSocketOper()
{
  GASocketOper *pSocketOper = [[GASocketOper alloc] init];
  return pSocketOper;
}

void SocketInterface_Free(void *apSocketOper)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper close];
  [pSocketOper release];
}

TBOOL SocketInterface_IsHaveConnect(void *apSocketOper)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  if ([pSocketOper isHaveConnect]==YES) {
    return TRUE;
  }

  return FALSE;
}

void SocketInterface_SetServerIPPort(void *apSocketOper,
                                     char* apServer,
                                     int anPort)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper setServerIPPort:apServer withPort:anPort];
  
}

void SocketInterface_ConnectToServer(void *apSocketOper)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper connectToServer];
}

void SocketInterface_Close(void *apSocketOper)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper close];
}

void SocketInterface_WriteBytes(void *apSocketOper,
                                char *apSendBuffer,
                                unsigned int anSize)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper writeBytes:apSendBuffer length:anSize];
  //NSLog(@"\n GA %@  %d\n",[NSString stringWithUTF8String:apSendBuffer],anSize);
}

void SocketInterface_SetStatusNotice(
    void *apSocketOper,
    GASocketOperNoticeCallBack* apNoticeCallBack)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper setStatusNotice:apNoticeCallBack];
}

void SocketInterface_SetUserIdAndSessionId(void *apSocketOper, long alUserId, char* apSessionId)
{
  GASocketOper *pSocketOper;
  pSocketOper = (GASocketOper*)apSocketOper;
  [pSocketOper setUserIdAndSessionId:alUserId withSession:apSessionId];
}
